package lexicalAnalysis.core;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.Scanner;

public class Reader {
	private static int pos;
	private char[] input;

	public Reader(File file) {
		try {
			input = convertInputStreamToString(new FileInputStream(file)).toCharArray();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	public char getNextChar() {
		if (pos < input.length) {
			return input[pos++];
		}
		return 0;
	}

	public void unGetChar() {
		pos--;
	}
	
	public boolean finish(){
		return pos>=input.length;
	}
	
	@SuppressWarnings("resource")
	private String convertInputStreamToString(InputStream in) {
		return new Scanner(in).useDelimiter("^").next();
	}
}
